package py.com.sole.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import py.com.sole.util.TipoPago;

@FacesConverter(value = "tipoPagoConverter")
public class TipoPagoConverter implements Converter {

  @Override
  public Object getAsObject(FacesContext context, UIComponent component,
                            String value) {

    if (value == null || value.equals("")) {
      return null;
    }

    TipoPago tipoPago = TipoPago.valueOf(value);
    return tipoPago;
  }

  @Override
  public String getAsString(FacesContext context, UIComponent component,
                            Object value) {
    if (value == null) {
      return null;
    }
    TipoPago tipoPago = (TipoPago) value;
    return tipoPago.name();
  }

}
